﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Ccit.OA.MsAddrBook;
using Newtonsoft.Json;
using System.Collections.Generic;
using Ccit.OA.Utils;
using Ccit.Utils;
namespace Ccit.OA.AddrBook
{
    public partial class addrbook_personal_edit : Ccit.Utils.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                _hidsRecId.Value = (Request.QueryString["Id"]!="0") ? Request.QueryString["Id"].ToString() : "";
                InitPage();
            }
            InitBinde();
        }
        private void InitPage()
        {
            LoginUser login = (LoginUser)HttpContext.Current.Session["LogUserInfo"];
            CtrInterface.BindDropDown(ref ddlMakeNum, "bas_a1", "bas_a1_30", "bas_a1_40", false, "", "bas_a1_20='997'");
            CtrInterface.BindDropDown(ref ddlGroup, "ADDR_A2", "ADDR_A2_10", "ADDR_A2_30", false, "","ADDR_A2_20="+login.UserId+"");
        }
        private void InitBinde()
        {
            if (_hidsRecId.Value!="")
            {
                AddrBookBLL Bll = new AddrBookBLL();
                MsAddBooks ms = Bll.GetEditAddBookMes(_hidsRecId.Value);
                if(ms!=null)
                {
                    txtName.Text = ms.Name;
                    txtCall.Text = ms.Call;
                    txtBirthDay.Text = ms.Birthday;
                    if (ms.GroupId!="")
                        ddlGroup.SelectedValue = ms.GroupId;
                    txtCompany.Text = ms.Company;
                    txtDeptName.Text = ms.DeptName;
                    txtPostName.Text = ms.PostName;
                    txtTelphone.Text = ms.Telphone;
                    txtComTel.Text = ms.Comtel;
                    txtFax.Text = ms.Fax;
                    txtFtel.Text = ms.Ftel;
                    ddlMakeNum.SelectedValue = ms.makenum;
                    txtPostCode.Text = ms.Postcode;
                    txtEmail.Text = ms.email;
                    txtMsnName.Text = ms.msnname;
                    txtQName.Text = ms.qname;
                    txtUrl.Text = ms.url;
                    txtRemark.Text = ms.remark;
                    txtMaddress.Text = ms.Maddress;
                }
            }
        }
        #region Ajax Methods
        [global::System.Web.Services.WebMethod]
        public static string DoSaveMes(string strJson, string cType)
        {
            AddrBookBLL Bll = new AddrBookBLL();
            MsAddBooks ms = (MsAddBooks)JavaScriptConvert.DeserializeObject(strJson, typeof(MsAddBooks));
            List<string> lstResult = Bll.DoSaveAddBookMes(ms);
            var newObj = new { result = lstResult[0], message = lstResult[1], ctrtype = cType };
            string serExpr = JavaScriptConvert.SerializeObject(newObj);
            Bll = null;
            newObj = null;
            return serExpr;
        }
        #endregion
    }
}
